/**
 * Created by chenzheyu on 2017/4/14.
 */
$(function () {
    var SEOval = '';
    var limit = 20;

    function xin() {
        $.ajax({
            url: ctx + '/rentorder/selectRentOrdersCount',
            type: 'GET',
            success: function (data) {
                var text = data.split(',');
                var li = $('.CustomTabs ul li');

                if (text[0] > 0) {
                    if (li.eq(0).find('.CustomBadge').length > 0) {
                        li.eq(0).find('.CustomBadge').remove();
                        li.eq(0).Badge({data: {text: text[0] > 99 ? '99+' : text[0], state: 'No'}})
                    } else {
                        li.eq(0).Badge({data: {text: text[0] > 99 ? '99+' : text[0], state: 'No'}})
                    }
                }

                if (text[1] > 0) {
                    if (li.eq(7).find('.CustomBadge').length > 0) {
                        li.eq(7).find('.CustomBadge').remove();
                        li.eq(7).Badge({data: {text: text[1] > 99 ? '99+' : text[1], state: 'No'}})
                    } else {
                        li.eq(7).Badge({data: {text: text[1] > 99 ? '99+' : text[1], state: 'No'}})
                    }
                }

                if (text[2] > 0) {
                    if (li.eq(8).find('.CustomBadge').length > 0) {
                        li.eq(8).find('.CustomBadge').remove();
                        li.eq(8).Badge({data: {text: text[2] > 99 ? '99+' : text[2], state: 'No'}})
                    } else {
                        li.eq(8).Badge({data: {text: text[2] > 99 ? '99+' : text[2], state: 'No'}})
                    }
                }
            }
        })
    }

    xin();
    setInterval(function () {
        xin()
    }, 60000);


    function ServiceOrder(page, SEOVal) {
        var ConfirmedOrderOptin = {
            plateNoOrPassengerPhone: SEOVal || '',
            status: 20,
            'limit': limit,
            'pager.offset': (page - 1) * limit
        };
        $.ajax({
            url: ctx + '/rentorder/selectRentOrders',
            data: ConfirmedOrderOptin,
            type: 'GET',
            success: function (data) {
                var option = {
                    data: {
                        Thead: {
                            PullDownAction: '操作',
                            OrderNumber: "单号",
                            totalFree:'总金额',
                            payed: '租金',
                            Store: "门店",
                            RetrievingMeans: "取车地址",
                            ReturnType: "还车地址",
                            HireTime: "还车时间",
                            reRentTime: "续租时间",
                            ResidueTime: "剩余时间",
                            ClientName: "客户名称",
                            ClientPhone: "客户电话",
                            Car: "车辆号牌",
                            CarType: "车辆类型",
                            // RentalStandard: "租金标准",
                            Prepayment: "租车押金",
                            ViolationMoneys: "违章押金",
                            // PrepayMoney: "预授金额",
                            SubordinateCompanies: "所属公司",
                            Remark: "备注"
                        },
                        Tbody: []
                    }
                };
                var PresentTimestamp = Date.parse(new Date()) / 1000;
                for (var i = 0; i < data.content.length; i++) {
                    (function () {
                        var index = i;
                        var val = {
                            id: data.content[index].id,
                            PullDownAction: {
                                Default: {
                                    name: '还车',
                                    action: function (e) {

                                        window.location.href = ctx + '/rentorder/backpay?id=' + data.content[index].id;

                                        // var huancheoption = {
                                        //     data: {
                                        //         Title: '还车提示',
                                        //         Content: '确认要还车？',
                                        //         OkChange: function (e) {
                                        //             var timestamp = Date.parse(new Date());
                                        //             var huanche = {
                                        //                 id: id,
                                        //                 backCarTime: timestamp/1000,
                                        //                 error: '2312',
                                        //                 errorImage: '123',
                                        //                 backCarEmploy: ''
                                        //             };
                                        //             $.ajax({
                                        //                 url: ctx+'/rentorder/back',
                                        //                 data: huanche,
                                        //                 type:'POST',
                                        //                 success: function (data) {
                                        //                     if(data.message=='订单状态修改成功'){
                                        //                         $('body').Overlays({data:{text:'还车成功！',state:'Ok'}});
                                        //                         ServiceOrder(1,SEOVal)
                                        //                     }else {
                                        //                         $('body').Overlays({data:{text:'还车失败，请稍后重试！',state:'No'}});
                                        //                         ServiceOrder(1,SEOVal)
                                        //                     }
                                        //                 }
                                        //             });
                                        //         }
                                        //     }
                                        // };
                                        // $('body').ModalBox(huancheoption)
                                    }
                                },
                                data: [
                                    {
                                        name: '续租',
                                        action: function (e) {
                                            var id = e.parent().parent().parent().parent().data('id');
                                            var reRentTime = '';
                                            var huancheoption = {
                                                data: {
                                                    Title: '车辆续租',
                                                    Content: '',
                                                    OkChange: function (e, Rmove) {
                                                        var reRentFee = e.find('.money').val();
                                                        var huanche = {
                                                            id: id,
                                                            reRentTime: reRentTime,
                                                            reRentFee: reRentFee
                                                        };
                                                        if (huanche.reRentFee == '' && !huanche.reRentFee) {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '填写续租金额！',
                                                                    state: 'No'
                                                                }
                                                            })
                                                            return;
                                                        }
                                                        $.ajax({
                                                            url: ctx + '/rentorder/applyReRent',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == "订单状态修改成功") {
                                                                    Rmove();
                                                                    ServiceOrder(1, SEOval);
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '续租成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    })
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '续租失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    })
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    },
                                                    CancelChange: function () {
                                                        $('body .datepicker').remove();
                                                    }
                                                },
                                                OKHide: true
                                            };

                                            var XZConent = $('<div class="XZConent"></div>');
                                            var UsedRows = $('<div class="Rows"><div class="Name">原还车时间：</div></div>');
                                            var RowsContent = $('<div class="RowsContent"></div>');
                                            var Input = $('<input type="text" class="UsedTime" disabled  ="disabled  ">').data('Time', data.content[index].rentTime).val(data.content[index].rentTime ? $().Timestamp.TimestampDate(data.content[index].rentTime) : '无');
                                            RowsContent.append(Input);
                                            UsedRows.append(RowsContent);
                                            XZConent.append(UsedRows);


                                            var UsedRows4 = $('<div class="Rows"><div class="Name">原续租时间：</div></div>');
                                            var RowsContent4 = $('<div class="RowsContent"></div>');
                                            var Input4 = $('<input type="text" class="UsedTime" disabled  ="disabled  ">').data('Time', data.content[index].reRentTime).val(data.content[index].reRentTime ? $().Timestamp.TimestampDate(data.content[index].reRentTime) : '无');
                                            RowsContent4.append(Input4);
                                            UsedRows4.append(RowsContent4);
                                            XZConent.append(UsedRows4);

                                            var NewRows = $('<div class="Rows"><div class="Name"><em>*</em>新续租时间：</div></div>');
                                            var RowsContent1 = $('<div class="RowsContent"></div>');
                                            var Input1 = $('<input type="text" class="NewTime">');
                                            RowsContent1.append(Input1);
                                            NewRows.append(RowsContent1);
                                            XZConent.append(NewRows);

                                            var ReletSumRows = $('<div class="Rows"><div class="Name"><em>*</em>续租金额：</div></div>');
                                            var RowsContent2 = $('<div class="RowsContent"></div>');
                                            var Input2 = $('<input type="number" class="money" placeholder="请输入续租金额">');
                                            RowsContent2.append(Input2);
                                            ReletSumRows.append(RowsContent2);
                                            XZConent.append(ReletSumRows);
                                            huancheoption.data.Content = XZConent;
                                            $('body').ModalBox(huancheoption);
                                            // console.log( $().Timestamp.TimestampDate(data.content[index].rentTime));
                                            Input1.datetimepicker({
                                                format: "yyyy-mm-dd HH:ii",
                                                language: 'zh-CN',
                                                showMeridian: true,
                                                autoclose: true,
                                                todayBtn: true,
                                                startDate:data.content[index].reRentTime? $().Timestamp.TimestampDate(data.content[index].reRentTime): $().Timestamp.TimestampDate(data.content[index].rentTime)
                                            }).on('change', function () {
                                                var Titme = $(this).val();
                                                reRentTime = $().Timestamp.DateTimestamp(Titme);
                                                if (reRentTime < Input.data('Time')) {
                                                    Input1.val('');
                                                    $('body').Overlays({
                                                        data: {
                                                            text: '请选择大于原还车时间的时间！',
                                                            state: 'No'
                                                        }
                                                    })
                                                }
                                            });


                                        }
                                    },
                                    {
                                        name: '违章',
                                        action: function (e) {

                                            function BreakRecord() {
                                                var id = e.parent().parent().parent().parent().data('id');
                                                $.ajax({
                                                    url: ctx + '/rentorder/selectRentOrder',
                                                    data: {
                                                        id: id
                                                    },
                                                    success: function (data) {
                                                        var Data = data;
                                                        $.ajax({
                                                            url: ctx + '/rentorder/selectPeccancysByOrderId',
                                                            data: {orderId: id},
                                                            success: function (data) {
                                                                var breakOption = {
                                                                    data: {
                                                                        Title: "违章记录",
                                                                        Content: {},
                                                                        OkChange: function (e) {
                                                                        }
                                                                    }
                                                                };
                                                                var CustomOrder = {
                                                                    data: {
                                                                        Thead: {
                                                                            BreakTime: '违章时间',
                                                                            BreakGrade: '违章分数',
                                                                            BreakMoney: '违章金额(元)',
                                                                            BreakDescribe: '违章描述',
                                                                            Dispose: '处理',
                                                                            InformClient: '通知客户'
                                                                        },
                                                                        Tbody: []
                                                                    }
                                                                };
                                                                for (var i = 0; i < data.length; i++) {
                                                                    (function () {
                                                                        var index = i;
                                                                        var PushOption = {
                                                                            id: data[index].id,
                                                                            BreakTime: $().Timestamp.TimestampDate(data[index].time),
                                                                            BreakGrade: data[index].deductMarks,
                                                                            BreakMoney: data[index].amerce,
                                                                            BreakDescribe: data[index].reason,
                                                                            ButtonAction: '',
                                                                            InformClient: '通知客户'
                                                                        };
                                                                        CustomOrder.data.Tbody.push(PushOption);
                                                                        var chuliSate = true;
                                                                        if (data[index].status == 0) {
                                                                            PushOption.ButtonAction = {
                                                                                name: '处理',
                                                                                Action: function (e) {

                                                                                    function chulifn() {
                                                                                        if (chuliSate) {
                                                                                            chuliSate = false;
                                                                                            var timestamp = (new Date()).valueOf();
                                                                                            var id = e.parent().parent().data('id');
                                                                                            var Dispose = {
                                                                                                data: {
                                                                                                    Title: '处理违章',
                                                                                                    Content: '确认这个违章已处理？',
                                                                                                    OkChange: function (e) {
                                                                                                        $.ajax({
                                                                                                            url: ctx + '/rentorder/postPeccancy',
                                                                                                            data: {
                                                                                                                id: id,
                                                                                                                status: 1
                                                                                                            },
                                                                                                            type: 'POST',
                                                                                                            success: function (data) {
                                                                                                                if (data.message == '修改状态成功') {
                                                                                                                    $('body').Overlays({
                                                                                                                        data: {
                                                                                                                            text: '处理违章成功！',
                                                                                                                            state: 'Ok'
                                                                                                                        }
                                                                                                                    });

                                                                                                                    $('body .CustomModalBox[custommodalboxlength="0"]').remove();
                                                                                                                    $('body .CustomModalBox[custommodalboxlength="1"]').remove();
                                                                                                                    BreakRecord()

                                                                                                                } else {
                                                                                                                    $('body').Overlays({
                                                                                                                        data: {
                                                                                                                            text: '处理违章失败，请稍后重试！',
                                                                                                                            state: 'No'
                                                                                                                        }
                                                                                                                    })
                                                                                                                }
                                                                                                            }
                                                                                                        });


                                                                                                    }
                                                                                                }
                                                                                            };
                                                                                            $('body').ModalBox(Dispose)
                                                                                            // $('body').ModalBox(Dispose);
                                                                                        }
                                                                                    }

                                                                                    chulifn()

                                                                                }
                                                                            }
                                                                        } else {
                                                                            PushOption.ButtonAction = '已处理'
                                                                        }
                                                                    })()
                                                                }


                                                                breakOption.data.Content = {
                                                                    CustomOrderAction: '<div class="BreakAction"><div class="BreakActionAdd">添加</div></div>',
                                                                    CustomOrder: '<div class="ServiceOrder"></div>'
                                                                };


                                                                $('body').ModalBox(breakOption);

                                                                $('body').find('.CustomModalBox').find('.ServiceOrder').Order(CustomOrder);

                                                                $('.CustomModalBox').find('.BreakActionAdd').on('click', function (e) {
                                                                    e.stopPropagation();
                                                                    {
                                                                        var BreakTitme = null;
                                                                        var Address = null;
                                                                        var Grade = null;
                                                                        var Money = null;
                                                                        var Describe = null;

                                                                        var breakOption1 = {
                                                                            data: {
                                                                                Title: "添加违章",
                                                                                Content: '',
                                                                                OkChange: function (e, Remove) {
                                                                                    if (BreakTitme && Address && Grade && Money && Describe) {
                                                                                        var BreakItmeDta = {
                                                                                            orderId: id,
                                                                                            passengerId: Data.passengerId,
                                                                                            time: BreakTitme,
                                                                                            deductMarks: Grade,
                                                                                            amerce: Money,
                                                                                            reason: Describe,
                                                                                            address: Address,
                                                                                            plateNo: Data.plateNo,
                                                                                            passengerName: Data.passengerName,
                                                                                            status: 0
                                                                                        };
                                                                                        $.ajax({
                                                                                            url: ctx + '/rentorder/addPeccancy',
                                                                                            data: BreakItmeDta,
                                                                                            type: 'POST',
                                                                                            success: function (data) {
                                                                                                console.log(data);
                                                                                                if (data.message == '创建成功') {
                                                                                                    $('body').Overlays({
                                                                                                        data: {
                                                                                                            text: '添加违章成功！',
                                                                                                            state: 'Ok'
                                                                                                        }
                                                                                                    });

                                                                                                    $('body .CustomModalBox[custommodalboxlength="0"]').remove();
                                                                                                    $('body .datepicker').remove();
                                                                                                    BreakTitme = null;
                                                                                                    Address = null;
                                                                                                    Grade = null;
                                                                                                    Money = null;
                                                                                                    Describe = null;
                                                                                                    Remove();
                                                                                                    BreakRecord();
                                                                                                } else {
                                                                                                    $('body').Overlays({
                                                                                                        data: {
                                                                                                            text: '添加违章失败，请稍后重试！',
                                                                                                            state: 'No'
                                                                                                        }
                                                                                                    })
                                                                                                }
                                                                                            }
                                                                                        });


                                                                                    } else {
                                                                                    	console.log(123)
                                                                                        $('body').Overlays({
                                                                                            data: {
                                                                                                text: '请检查您输入信息格式是否正确!',
                                                                                                state: 'No'
                                                                                            }
                                                                                        })
                                                                                    }
                                                                                },
                                                                                CancelChange: function () {
                                                                                    $('body .datepicker').remove();
                                                                                }
                                                                            },
                                                                            OKHide: true
                                                                        };


                                                                        var AddViolation = $('<div class="AddViolation"></div>');
                                                                        var Rows1 = $('<div  class="rows"></div>');
                                                                        var Name1 = $('<span class="RowsName"><em>*</em></span>').append('违章时间：');
                                                                        var BreakTime = $('<input  type="text" class="BreakTime">');
                                                                        
                                                                        var xianzaisj=new Date();
                                                                        var shijian=Date.parse(new Date(xianzaisj.getFullYear(),xianzaisj.getMonth(),(xianzaisj.getDate()+1),xianzaisj.getHours(),xianzaisj.getMinutes(),xianzaisj.getSeconds(),0))/1000;
                                                                        BreakTime.datetimepicker({
                                                                            format: "yyyy-mm-dd HH:ii",
                                                                            language: 'zh-CN',
                                                                            showMeridian: true,
                                                                            autoclose: true,
                                                                            todayBtn: true,
                                                                            endDate:$().Timestamp.TimestampDate(shijian)
                                                                        }).on('change', function () {
                                                                            var Titme = $(this).val();
                                                                            BreakTitme = $().Timestamp.DateTimestamp(Titme);
                                                                        });

                                                                        Rows1.append(Name1).append(BreakTime);
                                                                        AddViolation.append(Rows1);
                                                                        var Rows2 = $('<div  class="rows"></div>');
                                                                        var Name2 = $('<span class="RowsName"><em>*</em></span>').append('违章地址：');
                                                                        var BreakAddress = $('<input  type="text" class="BreakAddress">');
                                                                        Rows1.append(Name2).append(BreakAddress);
                                                                        AddViolation.append(Rows2);
                                                                        var Rows3 = $('<div  class="rows"></div>');
                                                                        var Name3 = $('<span class="RowsName"><em>*</em></span>').append('违章分数：');
                                                                        var BreakGrade = $('<input  type="number" class="BreakGrade">');

                                                                        Rows1.append(Name3).append(BreakGrade);
                                                                        AddViolation.append(Rows3);
                                                                        var Rows4 = $('<div  class="rows"></div>');
                                                                        var Name4 = $('<span class="RowsName"><em>*</em></span>').append('违章金额：');
                                                                        var BreakMoney = $('<input  type="number" class="BreakMoney">');
                                                                        Rows1.append(Name4).append(BreakMoney);
                                                                        AddViolation.append(Rows4);
                                                                        var Rows5 = $('<div  class="rows"></div>');
                                                                        var Name5 = $('<span class="RowsName"><em>*</em></span>').append('描述：');
                                                                        var BreakDescribe = $('<input  type="text" class="BreakDescribe">');
                                                                        Rows1.append(Name5).append(BreakDescribe);
                                                                        AddViolation.append(Rows5);
                                                                        breakOption1.data.Content = AddViolation;

                                                                        $('body').ModalBox(breakOption1);


                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakAddress', function () {
                                                                            Address = $(this).val();
                                                                        });
                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakGrade', function () {
                                                                            Grade = $(this).val();
                                                                        });
                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakMoney', function () {
                                                                            Money = $(this).val();
                                                                        });
                                                                        $(document).on('input', 'body .CustomModalBox[custommodalboxlength="1"] .BreakDescribe', function () {
                                                                            Describe = $(this).val();
                                                                        })
                                                                    }
                                                                })

                                                            }
                                                        });
                                                    }
                                                })
                                            }

                                            BreakRecord()
                                        }
                                    }
                                ]
                            },
                            OrderNumber: data.content[index].orderNo,
                            totalFree:data.content[i].totalFee,
                            payed: '',
                            Store: data.content[index].shopName,
                            RetrievingMeans: data.content[index].takeCarWay == 1 ? data.content[index].startAddress : "门店自取",
                            ReturnType: data.content[index].backCarWay == 1 ? data.content[index].endAddress : '门店自还',
                            HireTime: $().Timestamp.TimestampDate(data.content[index].rentTime),
                            ReturnTime: data.content[index].reRentTime ? $().Timestamp.TimestampDate(data.content[index].reRentTime) : '无续租',
                            ResidueTime: $().Timestamp.DayCalculate(data.content[index].reRentTime ? data.content[index].reRentTime - PresentTimestamp : data.content[index].rentTime - PresentTimestamp),
                            ClientName: data.content[index].passengerName,
                            ClientPhone: data.content[index].passengerPhone,
                            Car: data.content[index].plateNo,
                            CarType: data.content[index].category,
                            // RentalStandard: data.content[index].RentalStandard,
                            Prepayment: '',
                            ViolationMoneys: '',
                            // PrepayMoney: data.content[index].PrepayMoney,
                            SubordinateCompanies: data.content[index].companyName,
                            Remark: data.content[index].memo
                        };

                        switch (data.content[i].isPay) {
                            case 0:
                                val.payed = $('<span class="badge">未交付</span>');
                                break;
                            case 1:
                                val.payed = data.content[i].payed;
                                break;
                            case 2:
                                val.payed =data.content[i].payed;
                                break;
                            case 3:
                                val.payed = data.content[i].payed;
                                break;
                            case 4:
                                val.payed = '已结算';
                                break;
                        }

                        switch (data.content[index].isBackPrepayRent) {
                            case 0:
                                val.Prepayment = '未交付';
                                val.PullDownAction.data.push({
                                    name: '交租车押金',
                                    action: function (e) {

                                        var prepayRentTime = '';
                                        var prepayRent = '';
                                        var prepayRentType = 1;
                                        var yajinjiluData = {
                                            data: {
                                                Title: '交租车押金',
                                                Content: '',
                                                OkChange: function (e,Remove) {
                                                    var reRentTime = '';
                                                    var huanche;

                                                    function Ajax() {
                                                        $.ajax({
                                                            url: ctx + '/rentorder/deposit',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == "押金记录录入成功") {
                                                                	ServiceOrder(1, SEOval);
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加租车押金成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    ServiceOrder(1, SEOval);
                                                                    xin();
                                                                    Remove()
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加租车押金失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    })
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    }

                                                    if (prepayRentType == 1) {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            prepayRentTime: prepayRentTime,
                                                            prepayRent: prepayRent,
                                                            prepayRentType: prepayRentType
                                                        };
                                                        if(!huanche.prepayRent<=0 && !huanche.prepayRentTime==''){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    } else {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            prepayRent: prepayRent,
                                                            prepayRentType: prepayRentType
                                                        };
                                                        if(!huanche.prepayRent<=0){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    }




                                                    
                                                },
                                                CancelChange: function () {
                                                    $('body .datepicker').remove();
                                                }
                                            },
                                            OKHide:true,

                                        };


                                        var ModContent = $('<div class="ModContent"></div>');
                                        var YSRows = $('<div class="Rows"><div class="Name"><em>*</em>租车押金额度：</div></div>');
                                        var Content = $('<div class="RowsContent"><input class="YsInput" type="number" /></div>');
                                        Content.find('.YsInput').on('input', function () {
                                            prepayRent = $(this).val();
                                            if(prepayRent<0){
                                                $(this).val('');
                                                prepayRent=0;
                                            }
                                        });
                                        YSRows.append(Content);
                                        ModContent.append(YSRows);

                                        var YSRowsType = $('<div class="Rows"><div class="Name">交付类型：</div></div>');
                                        var Content2 = $('<div class="RowsContent CustomClear"><label><input class="rentCarInput" type="radio" name="rentCar" value="预授权" checked /><span>预授权交付</span></label><label><input class="rentCarInput" type="radio" name="rentCar" value="现金" /><span>现金交付</span></label></div>');
                                        YSRowsType.append(Content2);
                                        ModContent.append(YSRowsType);

                                        var TimeRows = $('<div class="Rows PreauthorizationTime"><div class="Name"><em>*</em>预授权到期时间：</div></div>');
                                        var Content1 = $('<div class="RowsContent"></div>');
                                        var TimeInput = $('<input class="TimeInput" type="text" readonly/>');
                                        var shijian=Date.parse(new Date())/1000;
                                        TimeInput.datetimepicker({
                                            format: "yyyy-mm-dd HH:ii",
                                            language: 'zh-CN',
                                            showMeridian: true,
                                            autoclose: true,
                                            todayBtn: true,
                                            startDate:$().Timestamp.TimestampDate(shijian)
                                        }).on('change', function () {
                                            var Titme = $(this).val();
                                            prepayRentTime = $().Timestamp.DateTimestamp(Titme);
                                        });
                                        Content1.append(TimeInput);
                                        TimeRows.append(Content1);
                                        ModContent.append(TimeRows);
                                        yajinjiluData.data.Content = ModContent;

                                        var rentCar = ModContent.find('.rentCarInput');
                                        for (var i = 0; i < rentCar.length; i++) {
                                            rentCar.eq(i).on('click', function () {
                                                switch ($(this).val()) {
                                                    case '预授权':
                                                        prepayRentType = 1;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'100','display': 'inline-block'});
                                                        break;
                                                    case '现金':
                                                        prepayRentType = 0;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'-100','display': 'none'});
                                                        break;
                                                }
                                            })
                                        }

                                        $('body').ModalBox(yajinjiluData);

                                    }
                                });
                                break;
                            case 1:
                                val.Prepayment = data.content[index].prepayRent;
                                break;
                            case 2:
                                val.Prepayment = '已退还';
                                break
                        }

                        switch (data.content[index].isBackPeccancyForegift) {
                            case 0:
                                val.ViolationMoneys = '未交付';
                                val.PullDownAction.data.push({
                                    name: '交违章押金',
                                    action: function (e) {


                                        var peccancyForegiftTime = '';
                                        var peccancyForegift = '';
                                        var peccancyForegiftType = 1;
                                        var yajinjiluData = {
                                            data: {
                                                Title: '交违章押金',
                                                Content: '',
                                                OkChange: function (e,Rmove) {
                                                    var reRentTime = '';
                                                    var huanche;


                                                    function Ajax() {
                                                        $.ajax({
                                                            url: ctx + '/rentorder/deposit',
                                                            data: huanche,
                                                            type: 'POST',
                                                            success: function (data) {
                                                                if (data.message == "押金记录录入成功") {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加违章押金成功！',
                                                                            state: 'Ok'
                                                                        }
                                                                    });
                                                                    ServiceOrder(1, SEOval);
                                                                    xin();
                                                                    Rmove()
                                                                } else {
                                                                    $('body').Overlays({
                                                                        data: {
                                                                            text: '添加违章押金失败，请稍后重试！',
                                                                            state: 'No'
                                                                        }
                                                                    })
                                                                }
                                                            }
                                                        });
                                                        $('body .datepicker').remove();
                                                    }
                                                    if (peccancyForegiftType == 1) {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            peccancyForegiftTime: peccancyForegiftTime,
                                                            peccancyForegift: peccancyForegift,
                                                            peccancyForegiftType: peccancyForegiftType,
                                                        };

                                                        if(!huanche.peccancyForegift<=0&&!huanche.peccancyForegiftTime==''){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    } else {
                                                        huanche = {
                                                            id: data.content[index].id,
                                                            peccancyForegift: peccancyForegift,
                                                            peccancyForegiftType: peccancyForegiftType,
                                                        };
                                                        if(!huanche.peccancyForegift<=0){
                                                            Ajax()
                                                        }else {
                                                            $('body').Overlays({
                                                                data: {
                                                                    text: '请检查信息是否填写完整！',
                                                                    state: 'No'
                                                                }
                                                            });
                                                        }
                                                    }



                                                },
                                                CancelChange: function () {
                                                    $('body .datepicker').remove();
                                                }
                                            },
                                            OKHide:true
                                        };


                                        var ModContent = $('<div class="ModContent"></div>');
                                        var YSRows = $('<div class="Rows"><div class="Name"><em>*</em>违章押金额度：</div></div>');
                                        var Content = $('<div class="RowsContent"><input class="YsInput" type="number" /></div>');
                                        Content.find('.YsInput').on('input', function () {
                                            peccancyForegift = $(this).val();
                                            if(peccancyForegift<0){
                                                peccancyForegift=0;
                                                $(this).val('');
                                            }
                                        });
                                        YSRows.append(Content);
                                        ModContent.append(YSRows);

                                        var YSRowsType = $('<div class="Rows"><div class="Name">交付类型：</div></div>');
                                        var Content2 = $('<div class="RowsContent CustomClear"><label><input class="rentCarInput" type="radio" name="rentCar" value="预授权" checked /><span>预授权交付</span></label><label><input class="rentCarInput" type="radio" name="rentCar" value="现金" /><span>现金交付</span></label></div>');
                                        YSRowsType.append(Content2);
                                        ModContent.append(YSRowsType);

                                        var TimeRows = $('<div class="Rows PreauthorizationTime"><div class="Name"><em>*</em>预授权到期时间：</div></div>');
                                        var Content1 = $('<div class="RowsContent"></div>');
                                        var TimeInput = $('<input class="TimeInput" type="text" readonly/>');
                                        var shijian=Date.parse(new Date())/1000;
                                        TimeInput.datetimepicker({
                                            format: "yyyy-mm-dd HH:ii",
                                            language: 'zh-CN',
                                            showMeridian: true,
                                            autoclose: true,
                                            todayBtn: true,
                                            startDate:$().Timestamp.TimestampDate(shijian)
                                        }).on('change', function () {
                                            var Titme = $('body .CustomModalBox[custommodalboxlength="0"] .TimeInput').val();
                                            peccancyForegiftTime = $().Timestamp.DateTimestamp(Titme);
                                        });
                                        Content1.append(TimeInput);
                                        TimeRows.append(Content1);
                                        ModContent.append(TimeRows);
                                        yajinjiluData.data.Content = ModContent;

                                        var rentCar = ModContent.find('.rentCarInput');
                                        for (var i = 0; i < rentCar.length; i++) {
                                            rentCar.eq(i).on('click', function () {
                                                switch ($(this).val()) {
                                                    case '预授权':
                                                        peccancyForegiftType = 1;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'100','display': 'inline-block'});;
                                                        break;
                                                    case '现金':
                                                        peccancyForegiftType = 0;
                                                        ModContent.find('.PreauthorizationTime').css({'opacity': 1,'z-index':'-100','display': 'none'});
                                                        break;
                                                }
                                            })
                                        }

                                        $('body').ModalBox(yajinjiluData);

                                    }
                                });
                                break;
                            case 1:
                                val.ViolationMoneys = data.content[index].peccancyForegift;
                                break;
                            case 2:
                                val.ViolationMoneys = '已退还';
                                break
                        }

                        option.data.Tbody.push(val)
                    })()
                }

                var PagingMdOption = {
                    data: {
                        rows: 20,
                        nowrows: page,
                        Pages: '',
                        total: data.totalElements,
                        change: function (index) {
                            ServiceOrder(index, SEOVal);
                        }
                    }
                };

                var CompletedContent = $('.Service .MidContent');
                CompletedContent.find('.CustomOrder').remove();
                CompletedContent.find('.PagingMdPagingMd').remove();
                CompletedContent.Order(option);
                CompletedContent.PagingMd(PagingMdOption)
            }
        })
    }

    ServiceOrder(1, SEOval);

    $(".Nav .SEO .SEOButton").on("click", function () {
        SEOval = $(".Nav .SEO  input").val();
        ServiceOrder(1, SEOval);
    });


    $(".Nav .SEO  input").keyup(function (event) {
        switch (event.keyCode) {
            case 13:
                $(".Nav .SEO .SEOButton").click();
                break;
        }
    });
});

